from PyQt5.QtWidgets import QMainWindow, QListWidget, QStackedWidget, QSplitter, QWidget, QHBoxLayout
from PyQt5.QtGui import QIcon
import os

from app.ui.audio_converter_widget import AudioConverterWidget
from app.ui.subtitles_widget import SubtitlesWidget
from app.ui.title_content_subtitles_widget import TitleContentSubtitlesWidget
from app.ui.video_audio_mux_widget import VideoAudioMuxWidget
from app.ui.subtitle_extractor_widget import SubtitleExtractorWidget
from app.ui.logo_adder_widget import LogoAdderWidget


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("工具集")

        icon_path = os.path.join(os.getcwd(), 'Rectifying.ico')
        if os.path.exists(icon_path):
            self.setWindowIcon(QIcon(icon_path))

        splitter = QSplitter(self)
        splitter.setHandleWidth(1)

        self.sidebar = QListWidget()
        self.sidebar.addItem("视频转音频")
        self.sidebar.addItem("视频加字幕")
        self.sidebar.addItem("视频字幕提取")
        self.sidebar.addItem("标题/内容加字幕")
        self.sidebar.addItem("音频视频合成")
        self.sidebar.addItem("增加Logo")
        self.sidebar.setFixedWidth(180)

        self.pages = QStackedWidget()
        self.video_page = AudioConverterWidget(self)
        self.subtitle_page = SubtitlesWidget(self)
        self.subtitle_extractor_page = SubtitleExtractorWidget(self)
        self.title_content_page = TitleContentSubtitlesWidget(self)
        self.mux_page = VideoAudioMuxWidget(self)
        self.logo_page = LogoAdderWidget(self)
        self.pages.addWidget(self.video_page)
        self.pages.addWidget(self.subtitle_page)
        self.pages.addWidget(self.subtitle_extractor_page)
        self.pages.addWidget(self.title_content_page)
        self.pages.addWidget(self.mux_page)
        self.pages.addWidget(self.logo_page)

        self.sidebar.currentRowChanged.connect(self.pages.setCurrentIndex)
        self.sidebar.setCurrentRow(0)

        splitter.addWidget(self.sidebar)
        splitter.addWidget(self.pages)
        splitter.setStretchFactor(1, 1)

        central = QWidget(self)
        layout = QHBoxLayout(central)
        layout.setContentsMargins(12, 12, 12, 12)
        layout.addWidget(splitter)
        central.setLayout(layout)
        self.setCentralWidget(central)

        self.resize(820, 420)


